﻿using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;

namespace DemoEf
{
    public class TestDbContext:DbContext
    {

        public DbSet<TbTest> TbTest { get; set; }


        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseBatchEF_MySQLPomelo();
            //var loggerFactory = new LoggerFactory();
            //loggerFactory.AddProvider(new EFCoreLoggerProvider());
            ////添加EnableSensitiveDataLogging，启用敏感数据记录
            //optionsBuilder.UseLoggerFactory(loggerFactory).EnableSensitiveDataLogging();
            //base.OnConfiguring(optionsBuilder);
        }

        public TestDbContext(DbContextOptions options) : base(options)
        {
            
        }

        

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<TbTest>(x =>
            {
                x.ToTable("TB_TEST");
                x.HasKey(x => x.Id);
                x.Property(x => x.Id).HasColumnName("id");
                x.Property(x => x.Name).HasColumnName("name");
                x.Property(x => x.Code).HasColumnName("code");
                x.Property(x => x.Time).HasColumnName("time");
            });
           // base.OnModelCreating(modelBuilder);
        }
    }


    public class TbTest
    {

        
        public string Id { get; set; }
        public string? Name { get; set; }
        public string Code { get; set; }

        public DateTime? Time { get; set; }
    }
}
